找传奇、传世资源到传世资源站!

简单实现圆形ImageView双层边框

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

简单实现圆形ImageView双层边框
from clipboardpackage com.example.test;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.PorterDuff.Mode;import android.graphics.PorterDuffXfermode;import android.graphics.RectF;import android.graphics.drawable.Drawable;import android.util.AttributeSet;import android.widget.ImageView;public class RoundImageView extends ImageView {private Paint paint;private Bitmap bmp;public RoundImageView(Context context) {super(context);// TODO Auto-generated constructor stubinit();}public RoundImageView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubinit();}public RoundImageView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}public void init() {paint = new Paint();paint.setAntiAlias(true);paint.setDither(true);paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));}@Overrideprotected void onDraw(Canvas canvas) {int w = getWidth();int h = getHeight();Drawable drawable = getDrawable();int i = canvas.saveLayer(0.0F, 0.0F, w, h, null, 31);int j = getWidth();int k = getHeight();drawable.setBounds(0, 0, j, k);drawable.draw(canvas);if (bmp == null){bmp = createMask();}canvas.drawBitmap(bmp, 0.0F, 0.0F, paint);canvas.restoreToCount(i);}public Bitmap createMask() {int i = getWidth();int j = getHeight();Bitmap.Config localConfig = Bitmap.Config.ARGB_8888;Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);Canvas localCanvas = new Canvas(localBitmap);Paint localPaint = new Paint(1);localPaint.setColor(-16777216);float f1 = getWidth();float f2 = getHeight();RectF localRectF = new RectF(0.0F, 0.0F, f1, f2);localCanvas.drawOval(localRectF, localPaint);return localBitmap;}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复